package com.zyf.wjy.dao;

import com.fasterxml.jackson.core.type.TypeReference;
import com.zyf.wjy.entity.SalesRecord;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 销售记录DAO
 */
@Repository
public class SalesRecordDao extends BaseDao<SalesRecord> {
    
    @Override
    protected String getFileName() {
        return "sales_records.json";
    }
    
    @Override
    protected TypeReference<List<SalesRecord>> getTypeReference() {
        return new TypeReference<List<SalesRecord>>() {};
    }
    
    @Override
    protected Long getId(SalesRecord entity) {
        return entity.getId();
    }
    
    @Override
    protected void setId(SalesRecord entity, Long id) {
        entity.setId(id);
    }
    
    /**
     * 根据产品ID查询
     */
    public List<SalesRecord> findByProductId(Long productId) {
        return findAll().stream()
            .filter(record -> productId.equals(record.getProductId()))
            .toList();
    }
    
    /**
     * 根据客户名称查询
     */
    public List<SalesRecord> findByCustomerName(String customerName) {
        return findAll().stream()
            .filter(record -> record.getCustomerName().contains(customerName))
            .toList();
    }
}

